*** Figure 3 ***

set scheme s2mono

********************************************************************************
*** Open ***
********************************************************************************
use "$data/simulated_df.dta", clear
keep if open==1
tab rank_v2, gen(time_dummies)
global dummies time_dummies1-time_dummies7 time_dummies9-time_dummies15
reghdfe any_post_total_patent1095 $dummies i.topic_n if $open_first & any_pre_total_allsbir==0, cluster(topic_n) absorb(topic_n)
 
	local var outcome 
	gen `var'_b = .
	gen `var'_sd = .
	gen `var'_u = .
	gen `var'_l = .
	
	* below
	forvalues x=5(1)7{
		local y = `x' - 4
		replace `var'_b=_b[time_dummies`x'] in `y'
		replace `var'_sd=_se[time_dummies`x'] in `y'
		replace `var'_u=_b[time_dummies`x']+1.96*_se[time_dummies`x'] in `y'
		replace `var'_l=_b[time_dummies`x']-1.96*_se[time_dummies`x'] in `y'
	}
	
	* Baseline
	replace `var'_b = 0 in 4
	
	* above
	forvalues x=9(1)12{
		local y = `x' - 4
		replace `var'_b=_b[time_dummies`x'] in `y'
		replace `var'_sd=_se[time_dummies`x'] in `y'
		replace `var'_u=_b[time_dummies`x']+1.96*_se[time_dummies`x'] in `y'
		replace `var'_l=_b[time_dummies`x']-1.96*_se[time_dummies`x'] in `y'
	}
	
	* Figure label cleanup
	gen n=_n
	label define betas 1 "-4" 2 "-3" 3 "-2" 4 "-1" 5 "1" 6 "2" 7 "3" 8 "4" , replace 
	label values n betas
		
	
	twoway (rcap `var'_u `var'_l n) (scatter `var'_b n, msize(medium) msymbol(circle) )  if n <= 8,  graphregion(color(white)) legend(off)  xlabel(1(1)8,valuelabel) title("") ytitle("Patent after Award Decision")  xtitle("Rank around Cutoff for Award")   yline(0 ) xline(4.5, lpattern(dash))

gr export "$figures/figure5a.eps", replace	

********************************************************************************
*** Conventional ***
********************************************************************************
use "$data/simulated_df.dta", clear
keep if conv==1 
tab rank_v2, gen(time_dummies)
global dummies time_dummies1-time_dummies34 time_dummies36-time_dummies53
reghdfe any_post_total_patent1095 $dummies if $conv17_first & any_pre_total_allsbir==0, cluster(topic_n) a(topic_n) 
 
	local var outcome 
	gen `var'_b = .
	gen `var'_sd = .
	gen `var'_u = .
	gen `var'_l = .
	
	* below
	forvalues x=32(1)34{
		local y = `x' - 31
		replace `var'_b=_b[time_dummies`x'] in `y'
		replace `var'_sd=_se[time_dummies`x'] in `y'
		replace `var'_u=_b[time_dummies`x']+1.96*_se[time_dummies`x'] in `y'
		replace `var'_l=_b[time_dummies`x']-1.96*_se[time_dummies`x'] in `y'
	}
	
	* Baseline
	replace `var'_b = 0 in 4
	
	* above
	forvalues x=36(1)39{
		local y = `x' - 31
		replace `var'_b=_b[time_dummies`x'] in `y'
		replace `var'_sd=_se[time_dummies`x'] in `y'
		replace `var'_u=_b[time_dummies`x']+1.96*_se[time_dummies`x'] in `y'
		replace `var'_l=_b[time_dummies`x']-1.96*_se[time_dummies`x'] in `y'
	}
	
	* Figure label cleanup
	gen n=_n
	label define betas 1 "-4" 2 "-3" 3 "-2" 4 "-1" 5 "1" 6 "2" 7 "3" 8 "4"  , replace 
	label values n betas
		
	
	twoway (rcap `var'_u `var'_l n) (scatter `var'_b n, msize(medium) msymbol(circle) )  if n <= 8,  graphregion(color(white)) legend(off)  xlabel(1(1)8,valuelabel) title("") ytitle("Patent after Award Decision")  xtitle("Rank around Cutoff for Award")   yline(0, lcolor(black) ) xline(4.5, lpattern(dash))  ylabel(-.5(0.25).5)
	
gr export "$figures/figure5b.eps", replace	
	
